﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Resources
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.Bindings;
using UnityEngineInternal;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>The Resources class allows you to find and access Objects including assets.</para>
  /// </summary>
  [NativeHeader("Runtime/Export/Resources/Resources.bindings.h")]
  [NativeHeader("Runtime/Misc/ResourceManagerUtility.h")]
  public sealed class Resources
  {
    internal static T[] ConvertObjects<T>(Object[] rawObjects) where T : Object
    {
      if (rawObjects == null)
        return (T[]) null;
      T[] objArray = new T[rawObjects.Length];
      for (int index = 0; index < objArray.Length; ++index)
        objArray[index] = (T) rawObjects[index];
      return objArray;
    }

    /// <summary>
    ///   <para>Returns a list of all objects of Type type.</para>
    /// </summary>
    /// <param name="type"></param>
    public static Object[] FindObjectsOfTypeAll(System.Type type)
    {
      return ResourcesAPI.ActiveAPI.FindObjectsOfTypeAll(type);
    }

    public static T[] FindObjectsOfTypeAll<T>() where T : Object
    {
      return Resources.ConvertObjects<T>(Resources.FindObjectsOfTypeAll(typeof (T)));
    }

    /// <summary>
    ///   <para>Loads an asset stored at path in a Resources folder using an optional systemTypeInstance filter.</para>
    /// </summary>
    /// <param name="path">Path to the target resource to load.</param>
    /// <param name="systemTypeInstance">Type filter for objects returned.</param>
    /// <returns>
    ///   <para>The requested asset returned as an Object.</para>
    /// </returns>
    public static Object Load(string path) => Resources.Load(path, typeof (Object));

    public static T Load<T>(string path) where T : Object => (T) Resources.Load(path, typeof (T));

    /// <summary>
    ///   <para>Loads an asset stored at path in a Resources folder using an optional systemTypeInstance filter.</para>
    /// </summary>
    /// <param name="path">Path to the target resource to load.</param>
    /// <param name="systemTypeInstance">Type filter for objects returned.</param>
    /// <returns>
    ///   <para>The requested asset returned as an Object.</para>
    /// </returns>
    public static Object Load(string path, System.Type systemTypeInstance)
    {
      return ResourcesAPI.ActiveAPI.Load(path, systemTypeInstance);
    }

    /// <summary>
    ///   <para>Asynchronously loads an asset stored at path in a Resources folder.</para>
    /// </summary>
    /// <param name="path">Pathname of the target folder. When using the empty string (i.e., ""), the function will load the entire contents of the Resources folder.</param>
    public static ResourceRequest LoadAsync(string path)
    {
      return Resources.LoadAsync(path, typeof (Object));
    }

    public static ResourceRequest LoadAsync<T>(string path) where T : Object
    {
      return Resources.LoadAsync(path, typeof (T));
    }

    /// <summary>
    ///   <para>Asynchronously loads an asset stored at path in a Resources folder.</para>
    /// </summary>
    /// <param name="path">Pathname of the target folder. When using the empty string (i.e., ""), the function will load the entire contents of the Resources folder.</param>
    /// <param name="systemTypeInstance">Type filter for objects returned.</param>
    /// <param name="type"></param>
    public static ResourceRequest LoadAsync(string path, System.Type type)
    {
      return ResourcesAPI.ActiveAPI.LoadAsync(path, type);
    }

    /// <summary>
    ///   <para>Loads all assets in a folder or file at path in a Resources folder.</para>
    /// </summary>
    /// <param name="path">Pathname of the target folder. When using the empty string (i.e., ""), the function will load the entire contents of the Resources folder.</param>
    /// <param name="systemTypeInstance">Type filter for objects returned.</param>
    public static Object[] LoadAll(string path, System.Type systemTypeInstance)
    {
      return ResourcesAPI.ActiveAPI.LoadAll(path, systemTypeInstance);
    }

    /// <summary>
    ///   <para>Loads all assets in a folder or file at path in a Resources folder.</para>
    /// </summary>
    /// <param name="path">Pathname of the target folder. When using the empty string (i.e., ""), the function will load the entire contents of the Resources folder.</param>
    /// <param name="systemTypeInstance">Type filter for objects returned.</param>
    public static Object[] LoadAll(string path) => Resources.LoadAll(path, typeof (Object));

    public static T[] LoadAll<T>(string path) where T : Object
    {
      return Resources.ConvertObjects<T>(Resources.LoadAll(path, typeof (T)));
    }

    [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
    [FreeFunction("GetScriptingBuiltinResource", ThrowsException = true)]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern Object GetBuiltinResource([NotNull("ArgumentNullException")] System.Type type, string path);

    public static T GetBuiltinResource<T>(string path) where T : Object
    {
      return (T) Resources.GetBuiltinResource(typeof (T), path);
    }

    /// <summary>
    ///   <para>Unloads assetToUnload from memory.</para>
    /// </summary>
    /// <param name="assetToUnload"></param>
    public static void UnloadAsset(Object assetToUnload)
    {
      ResourcesAPI.ActiveAPI.UnloadAsset(assetToUnload);
    }

    [FreeFunction("Scripting::UnloadAssetFromScripting")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void UnloadAssetImplResourceManager(Object assetToUnload);

    /// <summary>
    ///   <para>Unloads assets that are not used.</para>
    /// </summary>
    /// <returns>
    ///   <para>Object on which you can yield to wait until the operation completes.</para>
    /// </returns>
    [FreeFunction("Resources_Bindings::UnloadUnusedAssets")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern AsyncOperation UnloadUnusedAssets();

    /// <summary>
    ///   <para>Translates an instance ID to an object reference.</para>
    /// </summary>
    /// <param name="instanceID">Instance ID of an Object.</param>
    /// <returns>
    ///   <para>Resolved reference or null if the instance ID didn't match anything.</para>
    /// </returns>
    [FreeFunction("Resources_Bindings::InstanceIDToObject")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    public static extern Object InstanceIDToObject(int instanceID);

    [FreeFunction("Resources_Bindings::InstanceIDToObjectList")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void InstanceIDToObjectList(
      IntPtr instanceIDs,
      int instanceCount,
      List<Object> objects);

    public static unsafe void InstanceIDToObjectList(
      NativeArray<int> instanceIDs,
      List<Object> objects)
    {
      if (!instanceIDs.IsCreated)
        throw new ArgumentException("NativeArray is uninitialized", nameof (instanceIDs));
      if (objects == null)
        throw new ArgumentNullException(nameof (objects));
      if (instanceIDs.Length == 0)
        objects.Clear();
      else
        Resources.InstanceIDToObjectList((IntPtr) instanceIDs.GetUnsafeReadOnlyPtr<int>(), instanceIDs.Length, objects);
    }

    /// <summary>
    ///   <para>Returns a resource at an asset path (Editor Only).</para>
    /// </summary>
    /// <param name="assetPath">Pathname of the target asset.</param>
    /// <param name="type">Type filter for objects returned.</param>
    [Obsolete("Use AssetDatabase.LoadAssetAtPath instead (UnityUpgradable) -> * [UnityEditor] UnityEditor.AssetDatabase.LoadAssetAtPath(*)", true)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    [TypeInferenceRule(TypeInferenceRules.TypeReferencedBySecondArgument)]
    public static Object LoadAssetAtPath(string assetPath, System.Type type) => (Object) null;

    [EditorBrowsable(EditorBrowsableState.Never)]
    [Obsolete("Use AssetDatabase.LoadAssetAtPath<T>() instead (UnityUpgradable) -> * [UnityEditor] UnityEditor.AssetDatabase.LoadAssetAtPath<T>(*)", true)]
    public static T LoadAssetAtPath<T>(string assetPath) where T : Object => default (T);
  }
}
